package coms.dataaccess.hibernate;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import coms.dataaccess.ConferenceItemDAO;
import coms.datatransfer.ConferenceItemDTO;
import coms.exception.HibernateAccessLayerException;

public class ConferenceItemDAOImpl extends AbstractDAO implements ConferenceItemDAO {
	
	@Override
	public void insertConferenceItem(ConferenceItemDTO conferenceItem) {
		Logger.getLogger(getClass().getName()).log(Level.INFO, "Inserting File Item" + conferenceItem.getConferenceItemID());
		super.saveOrUpdate(conferenceItem);		
	}

	@Override
	public void updateConferenceItem(ConferenceItemDTO conferenceItem) {
		Logger.getLogger(getClass().getName()).log(Level.INFO, "Updating File Item" + conferenceItem.getConferenceItemID());
		super.saveOrUpdate(conferenceItem);		
	}

	@Override
	public void deleteConferenceItem(ConferenceItemDTO conferenceItem) {	
		
	}
	
	@SuppressWarnings("unchecked")
	public ConferenceItemDTO[] findAllConferenceItem() throws HibernateAccessLayerException {
        try {
        	ConferenceItemDTO[] result = null;;
            super.findAll(ConferenceItemDTO.class).toArray(result);
            return (result);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
        
    }
	
	@SuppressWarnings("unchecked")
	public List<Object[]> findAllConferenceItemByConfId(int ConferenceId) throws HibernateAccessLayerException {
        try {
        	List<Object[]> result = new ArrayList<Object[]>();
                  result = (List<Object[]>)super.manyToManyfindById(ConferenceItemDTO.class,"conferenceDTO", 
        			                                        "conferenceID", Integer.toString(ConferenceId));
        	System.out.println("size of confitems list"+ result.size());
        	return result;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }        
    }

}
